<template>
  <card-layout title="边坡性质" class="device-operation" bg="2">
    <template #extra>
      <el-button type="primary" size="small" @click="$emit('closeSlope',2)"><el-icon><SwitchButton /></el-icon>&nbsp; 关闭</el-button>
    </template>
    <div
      class="content"
      v-loading="loading"
      element-loading-background="rgba(255, 255, 255, 0.15)"
    >
      <!-- 储量饼图 -->
      <div class="chart-box">
        <div class="chart-title">矿山边坡性质分布饼状图</div>
        <div id="pieChartRef" class="chart"></div>
      </div>
      <!-- 数据 -->
      <div class="data-box">
        <div class="reserves-table">
          <el-table :data="tableData" :header-cell-style="headerCellStyle" border>
            <el-table-column prop="name" label="岩体分类" align="center"></el-table-column>
            <el-table-column prop="power" label="抗压强度" align="center"></el-table-column>
          </el-table>
        </div>
      </div>
    </div>
  </card-layout>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue';
import * as echarts from 'echarts';
import { Close } from '@element-plus/icons-vue';
import CardLayout from '@/layouts/CardLayout.vue';
const loading = ref(false);
// 使用 hooks 初始化图表
// const { chartInstance: pieChart } = useChart(pieChartRef);
// 总储量数据
const totalReserves = ref(0);
// 表格数据
const tableData = ref([
  {name:'硬岩', power:'> 60 Mpa'},
  {name:'软岩', power:'15 - 60 Mpa'},
  {name:'极软岩', power:'5 - 15 Mpa'}
]);
// 表格头部样式
const headerCellStyle = {
  background: 'rgba(0, 50, 50, 1)',
  color: '#fff',
  fontWeight: 'bold',
  borderColor: '#164b87'
};
let pieSlopeChart
let option = {
  legend: {
    orient: 'horizontal',
    bottom: '0px',
    left: 'center',
    itemWidth: 20,
    itemHeight: 10,
    textStyle: { //图例文字的样式
      color: '#eef1fa',
      fontSize: 14
    }
  },
  series: [
    {
      name: '性质类型',
      type: 'pie',
      itemStyle: {
        borderRadius: 2,
        borderColor: '#0a2e5c'
      },
      label: {
        normal: {
          show: true,
          position: 'outside',
          fontSize: 12,
          color: '#eef1fa',
        },
      },
      labelLine: {
        show: true
      },
      data: [
        { value: 1, name: '软岩', itemStyle: { color: '#5ad8a6' } },
        { value: 2, name: '硬岩', itemStyle: { color: '#5b8ff9' } }
      ]
    }
  ]
};

onMounted(() => {
  nextTick(()=>{
    pieSlopeChart = echarts.init(document.getElementById("pieChartRef"), null, {locale: 'ZH'});
    pieSlopeChart.setOption(option, true)
  })
});
</script>

<style lang="scss" scoped>
.device-operation {
  box-sizing: border-box;
  height: 100%;
  color: #fff;
  
  .content {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 10px;
    color: #eef1fa;
    .chart-box {
      border-radius: 4px;
      padding: 16px;
      display: flex;
      flex-direction: column;

      .chart-title {
        font-size: 16px;
        font-weight: bold;
        text-align: center;
      }

      .chart {
        height: 250px;
        width: 100%;
      }

      .legend {
        display: flex;
        justify-content: center;
        gap: 20px;
        margin-top: 16px;

        .legend-item {
          display: flex;
          align-items: center;
          gap: 8px;

          .color-block {
            width: 16px;
            height: 16px;
            border-radius: 4px;

            &.sand {
              background-color: #5ad8a6;
            }

            &.granite {
              background-color: #5b8ff9;
            }
          }
        }
      }
    }

    .data-box {
      display: flex;
      flex-direction: column;
      gap: 16px;

      .reserves-table {
        border-radius: 4px;
        padding: 5px;
        display: flex;
        flex-direction: column;
        min-height: 200px;
      }
    }
  }
}
</style>